package com.twu.biblioteca;

import com.twu.biblioteca.model.Book;
import com.twu.biblioteca.model.BookCollection;
import com.twu.biblioteca.model.Movie;
import com.twu.biblioteca.model.MovieCollection;
import com.twu.biblioteca.option.*;
import com.twu.biblioteca.util.MyScanner;

import java.io.PrintStream;
import java.util.*;

/**
 * Created by mvargas on 4/27/14.
 */
public class Menu {

    private final PrintStream printStream;
    private final Biblioteca biblioteca;
    private final BookCollection bookCollection;
    private final MyScanner scanner;
    private final MovieCollection movieCollection;


    private Map<Integer, String> options = new HashMap<Integer, String>();

    public Menu(Biblioteca biblioteca, PrintStream printStream, BookCollection bookCollection, MyScanner scanner, MovieCollection movieCollection){
        this.biblioteca = biblioteca;
        this.printStream = printStream;
        this.bookCollection = bookCollection;
        this.movieCollection = movieCollection;
        this.scanner = scanner;
        options.put(1,"Book List");
        options.put(2,"Movie List");
        options.put(3,"Membership Details");
        options.put(4,"Exit");
    }

    public String getOptionByKey(int key) {
        return this.options.get(key);
    }

    public void showMenuOptions(){
        printStream.println(this.getMenuOptions());
    }

    public String getMenuOptions() {
        Set<Integer> optionsKeySet = this.options.keySet();

        String outputMenuOptions = "\n";
        outputMenuOptions += "Menu:";
        for (Integer keyOption : optionsKeySet){
            outputMenuOptions += "\n";
            outputMenuOptions += keyOption+ ") " + getOptionByKey(keyOption);
        }
        return outputMenuOptions;
    }

    public void getMenuOptionSelected(Integer optionSelected) {
        Integer LIST_BOOK_OPTION = 1;
        Integer MEMBERSHIP_DETAIL_OPTION = 3;
        Integer MOVIE_LIST_OPTION = 2;
        Integer EXIT_OPTION = 4;

        if (optionSelected == LIST_BOOK_OPTION) {
            Option option = new ListBooksOption(bookCollection, scanner, printStream);
            option.execute();
        }else if (optionSelected == EXIT_OPTION){
            Option option = new ExitOption(biblioteca);
            option.execute();
        }else if (optionSelected == MEMBERSHIP_DETAIL_OPTION){
            Option option = new MembershipDetailOption(printStream);
            option.execute();
        }else if (optionSelected == MOVIE_LIST_OPTION){
            Option option = new MovieListOption(movieCollection, printStream);
            option.execute();
        }else{
            System.out.println("Select a valid option!!");
        }
    }




}